<?php 
namespace Home\Widget;
use Think\Controller;
class CompetitionregiWidget extends Controller {

    private $clash_transform = array(
        'f_a1' => 1,
        'f_a2' => 2,
        'f_a3' => 3,
        'f_a4' => 4,
        'f_b1' => 5,
        'f_b2' => 6,
        'f_b3' => 7,
        'f_b4' => 8,
        'f_c1' => 9,
        'f_c2' => 10,
        'f_c3' => 11,
        'f_c4' => 12,
        'f_d1' => 13,
        'f_d2' => 14,
        'f_d3' => 15,
        'f_d4' => 16,
        'f_e1' => 17,
        'f_e2' => 18,
        'f_e3' => 19,
        'f_f1' => 20,
        'f_f2' => 21,
        'f_f3' => 22,
        'f_g1' => 23,
        'f_g2' => 24,
        'f_g3' => 25,
        'f_h1' => 26,
        'f_h2' => 27,
        'f_h3' => 28
        );

    private $row_transform = array(
        0 => 0,
        1 => 0,
        2 => 0,
        3 => 0,
        4 => 9,
        5 => 8,
        6 => 8,
        7 => 8,
        8 => 9,
        9 => 8,
        10 => 8,
        11 => 8,
        12 => 8,
        13 => 8,
        14 => 8,
        15 => 8,
        16 => 9,
        17 => 8,
        18 => 8,
        19 => 8,
        20 => 8,
        21 => 8,
        22 => 8,
        23 => 8,
        24 => 8,
        );

    private $group_num_transform = array(
        0 => 0,
        1 => 0,
        2 => 0,
        3 => 0,
        4 => 0,
        5 => 2,
        6 => 2,
        7 => 2,
        8 => 2,
        9 => 3,
        10 => 4,
        11 => 4,
        12 => 4,
        13 => 4,
        14 => 4,
        15 => 4,
        16 => 4,
        17 => 6,
        18 => 6,
        19 => 8,
        20 => 8,
        21 => 8,
        22 => 8,
        23 => 8,
        24 => 8,
        );

	//前台加载竞赛详细内容
    public function competition_display($competition_id){
        //echo $competition_id;
        $this->competition = M('Competition_table')->where("competition_id=%d",$competition_id)->find();
        //var_dump($this->competition);
        $this->display('Competitionregi:middle');
    }

    //加载前台竞赛列表
    public function competition_home_list(){
    	$this->competition_list = M('Competition_table')->select();
    	//var_dump($this->competition_list);	
        $this->display('Competitionregi:com_list');
    }

    //加载竞赛成绩表(第一阶段)
    public function load_competition_result($competition_id,$mod_item) {
       //$competition_id." ".$mod_item;
       $this->assign($mod_item);
       $this->competition = M('Competition_table')->where("competition_id=%d",$competition_id)->find();       
       $group_count=array();
       //var_dump($this->competition);
       //exit();
       if(intval($this->competition['competition_status'])<=1) {
           echo "竞赛正在申请或报名中!<br />";
           return;
       } 
       //统计各组队伍数
       $com_f_clash_model = M('competition_firststep_clash_model')->where('com_f_clash_unit_number=%d',$this->competition['competition_regist_unit'])->find();
       $group_count = array('a'=>0,'b'=>0,'c'=>0,'d'=>0,'e'=>0,'f'=>0,'g'=>0,'h'=>0);
       foreach ($com_f_clash_model as $key => $value) {
            if($key!='com_f_clash_id' && $key!='com_f_clash_unit_number' && $value=='1') {
                $num = $this->clash_transform[$key];
                if($num>=1&&$num<=4){
                    $group_count['a']++;
                }else if($num>=5&&$num<=8){
                    $group_count['b']++;
                }else if($num>=9&&$num<=12){
                    $group_count['c']++;
                }else if($num>=13&&$num<=16){
                    $group_count['D']++;
                }else if($num>=17&&$num<=19){
                    $group_count['e']++;
                }else if($num>=20&&$num<=22){
                    $group_count['f']++;
                }else if($num>=23&&$num<=25){
                    $group_count['g']++;
                }else if($num>=26&&$num<=28){
                    $group_count['h']++;
                }
            }
        }
        $this->assign('group_count',$group_count);
        $this->assign('cols',$this->row_transform[$this->competition['competition_regist_unit']]);   
        $this->display('Competitionregi:com_f_group_clash_result');
    }

    //调用组别对应的模块
    public function load_clash_part($group,$count,$mod_item) {
       if($count!=0){
           $this->assign('mod_item',$mod_item);
           $this->display('Competitionregi:com_f_'.$group.'_'.$count.'row');
       } 
       
    }

    public function load_competition_secondstep_result($competition_id,$mod_item) {
        $this->assign('mod_item',$mod_item);
        $this->competition = M('Competition_table')->where("competition_id=%d",$competition_id)->find();       
        $group_num = $this->group_num_transform[$this->competition['competition_regist_unit']];
        $this->display('Competitionregi:com_s_'.$group_num.'group_clash');
        //$this->display('Competitionregi:com_s_'.'8'.'group_clash');
    }
   

}

 ?>


